/*
Delete all but the 10 oldest
--*/

--sp_helptext USP_CONSTITUENT_DELETE

declare @deletethese table (id uniqueidentifier);
insert into @deletethese
select id
from CONSTITUENT
where isactive = 1
  and ID not in(
select top 10 id
from CONSTITUENT
where ISACTIVE = 1
order by dateadded
)
select * from @deletethese

while (0 < (select COUNT(*) from @deletethese)) begin
  declare @currid uniqueidentifier = (select top 1 id from @deletethese)
  exec USP_CONSTITUENT_DELETE @currid;
  delete @deletethese where id = @currid;
end